package mongo

import (
	"context"
	"go.mongodb.org/mongo-driver/bson"
)

func FindById(colName, id string, T interface{}) error {
	var col = Db.Collection(colName)
	filter := bson.M{"_id": id}
	var sr = col.FindOne(context.TODO(), filter)
	if sr.Err() != nil {
		return sr.Err()
	} else {
		err := sr.Decode(T)
		if err != nil {
			return err
		}
	}
	return nil
}
